//
//  PowerViewController.m
//  MoXiProject
//
//  Created by 周筱雯 on 2017/6/30.
//  Copyright © 2017年 周筱雯. All rights reserved.
//

#import "PowerViewController.h"
#import "PowerCell.h"
#import "UserDetailViewController.h"

#import "GreatGodViewModel.h"
#import "GreatGodModel.h"

@interface PowerViewController ()
<
    UITableViewDelegate,
    UITableViewDataSource
>

@property (nonatomic,strong) UITableView * tableView;
@property (nonatomic,strong) GreatGodViewModel * greatViewModel;

@end

@implementation PowerViewController

-(GreatGodViewModel *) greatViewModel{
    if (!_greatViewModel) {
        _greatViewModel  = [[GreatGodViewModel alloc] init];
    }
    return _greatViewModel;
}


-(UITableView *) tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, DEF_DEVICE_WIDTH, DEF_CONTENT_INTABBAR_HEIGHT) style:UITableViewStylePlain];
        [_tableView setDelegate:self];
        [_tableView setDataSource:self];
        
        [MXUtility setExtraCellLineHidde:_tableView tabHeader:NO tabFooter:NO];
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.navigationItem setTitle:@"实力榜"];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:self.tableView];
  
    /**
     实力榜网络请求
     */
    [self powerNetWork];
}

-(void) powerNetWork{
    
    [MXUtility showMBProgress:self.view message:LoadingText];
    [[self.greatViewModel findUserBuyInfoRequestParameter:@"3"] subscribeNext:^(id x) {
        
        [self.tableView reloadData];
        [MXUtility hideMBProgress:self.view];
    }error:^(NSError *error) {
        
        [MXUtility hideMBProgress:self.view];
    }];
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.greatViewModel.finduserArrayList count];;
}
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * str = @"cell";
    PowerCell * cell = [tableView dequeueReusableCellWithIdentifier:str];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"PowerCell" owner:self options:nil] lastObject];
    }
    GreatGodModel * model = [self.greatViewModel.finduserArrayList objectAtIndex:indexPath.row];
    [cell setPowerCellDataSource:model index:indexPath];
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    UserDetailViewController * userdetail = [[UserDetailViewController alloc] init];
    
    GreatGodModel * model = [self.greatViewModel.finduserArrayList objectAtIndex:indexPath.row];
    [userdetail setUserID:model.greatuserId];
    
    [self.navigationController pushViewController:userdetail animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
